package com.briup.jdk8.day03;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 作业14最后一道题H
 */
public class Test6 {
    public static void main(String[] args) {
        Map<String, List<Course>> collect = getStudents().stream()
                //.distinct()
                .collect(Collectors.toMap(Student::getName, Student::getCourses,(u,v) -> v,TreeMap::new));

        collect.forEach((k,v)-> System.out.println(k+" : "+v));
    }
    public static List<Student>getStudents(){
        //创建课程
        Course JavaSE=new Course(1L,"Java基础","JavaSE");
        Course JavaEE=new Course(2L,"Java_Web应用开发","JavaEE");
        Course mysql=new Course(3L,"MySQL","MySQL数据库");
        Course oracle=new Course(4L,"Oracle","Oracle数据库");
        Course spring=new Course(5L,"Spring","Spring框架");
        Course springMVC=new Course(6L,"SpringMVC","SpringMVC框架");
        Course mybatis=new Course(7L,"Mybatis","Mybatis持久层框架");
        //创建课程集合
        List<Course>tomCourses= Arrays.asList(JavaSE,JavaEE,oracle,
                                spring,springMVC,mybatis);
        List<Course>aliCourses=Arrays.asList(JavaSE,JavaEE,mysql,
                spring,springMVC,mybatis);
        List<Course>queenieCourses=Arrays.asList(JavaSE,JavaEE,
                mysql,oracle,spring,mybatis);
        List<Course>nicoleCourses=Arrays.asList(JavaSE,JavaEE,
                mysql,oracle,spring,springMVC,mybatis);
        List<Course>jimmyCourses=Arrays.asList(JavaSE,JavaEE,
                oracle,spring,springMVC);
        List<Course>wendyCourses=Arrays.asList(JavaSE,mysql,
                oracle,spring,springMVC,mybatis);
        //创建学生对象
        Student tom=new Student(243701L,"Tom","男",18,tomCourses);
        Student ali=new Student(243702L,"Ali","男",23,aliCourses);
        Student queenie=new Student(243703L,"Queenie","女", 20,queenieCourses);
        Student nicole=new Student(243704L,"Nicole","女", 19,nicoleCourses);
        Student jimmy=new Student(243705L,"Jimmy","男", 22,jimmyCourses);
        Student wendy=new Student(243705L,"Wendy","女", 17,wendyCourses);
        //返回集合
        return Arrays.asList(tom,tom,ali,queenie,nicole,jimmy,wendy);
    }
}
class Student{
    private Long SchoolNumber;
    private String name;
    private String gender;
    private Integer age;
    private List<Course> courses;

    public Student() {
    }

    public Student(Long schoolNumber, String name, String gender, Integer age, List<Course> courses) {
        SchoolNumber = schoolNumber;
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.courses = courses;
    }

    public Long getSchoolNumber() {
        return SchoolNumber;
    }

    public void setSchoolNumber(Long schoolNumber) {
        SchoolNumber = schoolNumber;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public List<Course> getCourses() {
        return courses;
    }

    public void setCourses(List<Course> courses) {
        this.courses = courses;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(SchoolNumber, student.SchoolNumber) && Objects.equals(name, student.name) && Objects.equals(gender, student.gender) && Objects.equals(age, student.age) && Objects.equals(courses, student.courses);
    }

    @Override
    public int hashCode() {
        return Objects.hash(SchoolNumber, name, gender, age, courses);
    }

    @Override
    public String toString() {
        return "Student{" +
                "SchoolNumber=" + SchoolNumber +
                ", name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", age=" + age +
                ", courses=" + courses +
                '}';
    }
}
class Course{
    private Long id;
    private String name;
    private String info;

    public Course() {
    }

    public Course(Long id, String name, String info) {
        this.id = id;
        this.name = name;
        this.info = info;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Course course = (Course) o;
        return Objects.equals(id, course.id) && Objects.equals(name, course.name) && Objects.equals(info, course.info);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, info);
    }

    @Override
    public String toString() {
        return "Course{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", info='" + info + '\'' +
                '}';
    }
}
